//
//  LSOAViewController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/21.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSOAViewController.h"
#import "HomeButton.h"

#import "LSNotiViewController.h"//通知公告控制器
#import "LSNewsViewController.h"//新闻动态控制器
#import "LSPolicyLawsViewController.h"//政策法规控制器

#import "LSAttendanceManagementController.h"//考勤管理控制器
#import "LSWorkDayReportViewController.h"//工作日志控制器

@interface LSOAViewController ()
@property (nonatomic, strong) UIScrollView *mainScrollView;
@property (nonatomic, strong) NSArray *categoryArray;
@property (nonatomic, strong) NSArray *messageArrangeArray;
@property (nonatomic, strong) NSArray *examineApproveArray;
@property (nonatomic, strong) NSArray *otherFunctionArray;
@end

@implementation LSOAViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"移动OA";
    [self.view addSubview:self.mainScrollView];
    [self setUpUI];
}

- (void)setUpUI {
    // 消息管理视图
    NSInteger messageArrangeIndex = self.messageArrangeArray.count % 4;
    NSInteger messageArrangePage = self.messageArrangeArray.count / 4;
    if (messageArrangeIndex > 0) {
        messageArrangePage ++;
    }
    UIView *messageArrangeView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, ScreenWidth, 17+63*messageArrangePage+10)];
    messageArrangeView.backgroundColor = UIColor.whiteColor;
    [self.mainScrollView addSubview:messageArrangeView];
    UILabel *messageArrangeTipLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, ScreenWidth-50, 22) andText:@"消息管理" andTextColor:hexColor(333333) andFont:[UIFont fontWithName:@"SourceHanSansCN-Regular" size:15] andTextAlignment:NSTextAlignmentLeft];
    [messageArrangeView addSubview:messageArrangeTipLabel];
    for (int i = 0; i < self.messageArrangeArray.count; i++) {
        NSInteger index = i % 4;
        NSInteger page = i / 4;
        NSDictionary *dict = self.messageArrangeArray[i];
        UITapGestureRecognizer *messageArrangeTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(messageArrangeTapped:)];
        HomeButton *homeButton = [[HomeButton alloc] initWithFrame:CGRectMake(25+80*index, 22+4+58*page, 40, 58)];
        [homeButton addGestureRecognizer:messageArrangeTap];
        homeButton.tag = i + TagFoundation;
        homeButton.imageView.image = [UIImage imageNamed:dict[@"image"]];
        homeButton.titleLabel.text = dict[@"title"];
        [messageArrangeView addSubview:homeButton];
    }
    // 查阅审批视图
//    NSInteger examineApproveIndex = self.examineApproveArray.count % 4;
//    NSInteger examineApprovePage = self.examineApproveArray.count / 4;
//    if (examineApproveIndex > 0) {
//        examineApprovePage ++;
//    }
//    UIView *examineApproveView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(messageArrangeView.frame) + 10, ScreenWidth, 17+63*examineApprovePage+10)];
//    examineApproveView.backgroundColor = UIColor.whiteColor;
//    [self.mainScrollView addSubview:examineApproveView];
//    UILabel *examineApproveTipLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, ScreenWidth-50, 22) andText:@"查阅审批" andTextColor:hexColor(333333) andFont:[UIFont fontWithName:@"SourceHanSansCN-Regular" size:12] andTextAlignment:NSTextAlignmentLeft];
//    [examineApproveView addSubview:examineApproveTipLabel];
//    for (int i = 0; i < self.examineApproveArray.count; i++) {
//        NSInteger index = i % 4;
//        NSInteger page = i / 4;
//        NSDictionary *dict = self.examineApproveArray[i];
//        HomeButton *homeButton = [[HomeButton alloc] initWithFrame:CGRectMake(25+80*index, 22+4+58*page, 40, 58)];
//        homeButton.imageView.image = [UIImage imageNamed:dict[@"image"]];
//        homeButton.titleLabel.text = dict[@"title"];
//        [examineApproveView addSubview:homeButton];
//    }
    // 其他功能视图
    NSInteger otherFunctionIndex = self.otherFunctionArray.count % 4;
    NSInteger otherFunctionPage = self.otherFunctionArray.count / 4;
    if (otherFunctionIndex > 0) {
        otherFunctionPage ++;
    }
    UIView *otherFunctionView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(messageArrangeView.frame) + 10, ScreenWidth, 17+63*otherFunctionPage+10)];
    otherFunctionView.backgroundColor = UIColor.whiteColor;
    [self.mainScrollView addSubview:otherFunctionView];
    UILabel *otherFunctionTipLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, ScreenWidth-50, 22) andText:@"其他功能" andTextColor:hexColor(333333) andFont:[UIFont fontWithName:@"SourceHanSansCN-Regular" size:15] andTextAlignment:NSTextAlignmentLeft];
    [otherFunctionView addSubview:otherFunctionTipLabel];
    for (int i = 0; i < self.otherFunctionArray.count; i++) {
        NSInteger index = i % 4;
        NSInteger page = i / 4;
        NSDictionary *dict = self.otherFunctionArray[i];
        UITapGestureRecognizer *otherFunctionTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(otherFunctionTapped:)];
        HomeButton *homeButton = [[HomeButton alloc] initWithFrame:CGRectMake(25+80*index, 22+4+58*page, 40, 58)];
        [homeButton addGestureRecognizer:otherFunctionTap];
        homeButton.tag = i + TagFoundation;
        homeButton.imageView.image = [UIImage imageNamed:dict[@"image"]];
        homeButton.titleLabel.text = dict[@"title"];
        [otherFunctionView addSubview:homeButton];
    }
    // 设置scrollview的content
    self.mainScrollView.contentSize = CGSizeMake(ScreenWidth, CGRectGetMaxY(otherFunctionView.frame)+10);
}

// 消息管理按钮点击事件
- (void)messageArrangeTapped:(UITapGestureRecognizer *)tap {
    HomeButton *homeButton = (HomeButton *)tap.view;
    NSInteger tag = homeButton.tag - TagFoundation;
    switch (tag) {
        case 0: {
            // 通知公告
            LSNotiViewController *notiVC = [[LSNotiViewController alloc] initWithTabbar:false];
            [self.navigationController pushViewController:notiVC animated:true];
        }
            break;
        case 1: {
            // 新闻动态
            LSNewsViewController *newsVC = [[LSNewsViewController alloc] init];
            [self.navigationController pushViewController:newsVC animated:true];
        }
            break;
        case 2: {
            // 政策法规
            LSPolicyLawsViewController *policyLawsVC = [[LSPolicyLawsViewController alloc] init];
            [self.navigationController pushViewController:policyLawsVC animated:true];
        }
            break;
        default:
            break;
    }
}

// 其他功能按钮点击事件
- (void)otherFunctionTapped:(UITapGestureRecognizer *)tap {
    HomeButton *homeButton = (HomeButton *)tap.view;
    NSInteger tag = homeButton.tag - TagFoundation;
    switch (tag) {
        case 0: {
            // 考勤管理
            LSAttendanceManagementController *attendanceManagementVC = [[LSAttendanceManagementController alloc] init];
            [self.navigationController pushViewController:attendanceManagementVC animated:true];
        }
            break;
        case 1: {
            // 请假
            LSWorkDayReportViewController *workDayReportVC = [[LSWorkDayReportViewController alloc] init];
            [self.navigationController pushViewController:workDayReportVC animated:true];
        }
            break;
//        case 2: {
//            // 工作日志
//            LSWorkDayReportViewController *workDayReportVC = [[LSWorkDayReportViewController alloc] init];
//            [self.navigationController pushViewController:workDayReportVC animated:true];
//        }
//            break;
//        case 3:
//            // 绩效考核
//            break;
        default:
            break;
    }
}

- (UIScrollView *)mainScrollView {
    if (!_mainScrollView) {
        _mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight)];
        _mainScrollView.backgroundColor = hexColor(EEEEEE);
    }
    return _mainScrollView;
}

- (NSArray *)messageArrangeArray {
    if (!_messageArrangeArray) {
        _messageArrangeArray = @[@{@"image":@"tzgg",@"title":@"通知公告"},@{@"image":@"xwdt",@"title":@"新闻动态"},@{@"image":@"zcfg",@"title":@"政策法规"}];
    }
    return _messageArrangeArray;
}

- (NSArray *)examineApproveArray {
    if (!_examineApproveArray) {
        _examineApproveArray = @[@{@"image":@"wspd",@"title":@"我审批的"},@{@"image":@"wfqd",@"title":@"我发起的"},@{@"image":@"cswd",@"title":@"抄送我的"}];
    }
    return _examineApproveArray;
}

- (NSArray *)otherFunctionArray {
    if (!_otherFunctionArray) {
        _otherFunctionArray = @[@{@"image":@"kqgl",@"title":@"考勤管理"},@{@"image":@"gzrz",@"title":@"工作日志"}];//,@{@"image":@"jxkh",@"title":@"绩效考核"}
    }
    return _otherFunctionArray;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
